<template>
  <div id="RoomInfo" class="page-wrapper">
    <h1 class="main-title">基础设置</h1>
    <div class="selector-wrapper main-card wrapper">
      <div class="main-card"></div>
      <el-button type="primary" @click="handleSubmitClick">添加</el-button>
    </div>
    <div class="wrapper">
      <PanelGroup :roomInfo="roomInfo" :adminName="adminName" />
    </div>
    <div class="wrapper main-card">
      <!-- Listen for the 'refresh-data' event emitted by the child component -->
      <carousel :table-data="carouselinfo" @refresh-data="fetchData" />
    </div>
    <!-- 商品详情弹窗 -->
    <el-dialog
      title="填写广播内容"
      :visible.sync="dialogVisible"
      width="800px"
      height="800px"
    >
      <el-form class="form" ref="form" :model="modifydata">
        <div class="form-item-wrapper">
          <!-- <el-form-item label="id">
            <el-input v-model="carouselinfo.id" placeholder="输入id"></el-input>
          </el-form-item> -->
          <el-form-item label="内容">
            <el-input
              v-model="carouselinfo.content"
              placeholder="输入广播内容"
            ></el-input>
          </el-form-item>
          <!-- <el-form-item label="状态">
            <el-radio-group v-model="carouselinfo.status">
              <el-radio :label="1">使用中</el-radio>
              <el-radio :label="0">已禁止</el-radio>
            </el-radio-group>
          </el-form-item> -->
        </div>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="dialogVisible = false">取消</el-button>
        <el-button type="primary" @click="handleSubmit">确定</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
import carousel from './components/UserTable'
import { addbroadcast } from '@/api/pcclinet'

export default {
  name: 'RoomInfo',
  components: {
    carousel
  },
  data() {
    return {
      dialogVisible: false,
      carouselinfo: {}, // 存储轮播信息
      dialogdata: {} // 弹窗数据
    }
  },
  mounted() {
    this.fetchData() // 组件挂载时获取数据
  },
  methods: {
    // 获取服务器数据
    fetchData() {
      this.carouselinfo ={
        id: '',
        content: '',
        status: ''
      }
      addbroadcast(this.carouselinfo).then(res => {
        this.carouselinfo = res.data.allbroadcast // 将服务器返回的数据存储到carouselinfo
        //  console.log(this.carouselinfo)
      })
    
    },
    handleSubmitClick() {
      this.dialogVisible = true // 打开弹窗
    },

    // 提交表单并上传文件
    handleSubmit() {
      const data={
        id:   this.carouselinfo.id,
        content:   this.carouselinfo.content,
        status:   this.carouselinfo.status
      }
      addbroadcast(data).then(res => {
        this.carouselinfo = res.data.updatedBroadcast // 将服务器返回的数据存储到carouselinfo
        //  console.log(this.carouselinfo)
      })
      this.dialogVisible = false
      this.fetchData()
    }
  }
}
</script>

<style lang="scss" scoped>
#RoomInfo {
  .qianru {
    color: #fff;
    background-color: #1890ff;
    float: right;
  }
  > .wrapper {
    margin: 40px 0;
  }
  .selector-wrapper {
    display: flex;
    justify-content: space-between;
    align-items: center; // 垂直居中
  }
  .form-wrapper {
    margin-bottom: 40px;
    .btn-wrapper {
      display: flex;
      flex-direction: row-reverse;
    }
  }
  .search-wrapper {
    display: flex;
  }
  .el-select {
    display: block;
    position: relative;
  }
  .button-wrapper {
    display: flex;
    justify-content: flex-end; // 靠右对齐
    align-items: center; // 垂直居中
  }
}
.upload-demo {
  width: 100%;
}
.preview-image {
  width: 100px;
  height: 100px;
  object-fit: cover; // 保持图片比例
}
.preview-video {
  width: 300px;
  height: 200px;
}
</style>
